#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string convert(string s, int numRows)
    {
        int n = s.size();
        if (numRows == 1 || n == 1) return s;

        int a[1000][1000] = { 0 };
        int x = 0, y = 0;
        for (int i = 0; i < n;)
        {
            while (i < n && x < numRows - 1)
            {
                a[x][y] = s[i++];
                x++;
            }
            while (i < n && x > 0)
            {
                a[x][y] = s[i++];
                x--, y++;
            }
        }

        string ret = "";
        for (int i = 0; i < numRows; i++)
        {
            for (int j = 0; j < n / 2 + 1; j++)
            {
                if (a[i][j] != 0) ret += a[i][j];
            }
        }

        return ret;
    }
};